<?php namespace Summer\Hjd\Models;

use Model;
use Config;
use RainLab\User\Models\User as UserModel;

/**
 * Model
 */
class RgRecordModel extends Model
{
    use \Winter\Storm\Database\Traits\Validation;
    

    /**
     * @var string The database table used by the model.
     */
    public $table = 'summer_hjd_rg_record';

    /**
     * @var array Validation rules
     */
    public $rules = [
    ];

    public $belongsTo = [
        'currency' => ['Summer\Hjd\Models\CurrencyModel', 'key' => 'currency_slug', 'otherKey' => 'slug'],
        'target' => ['RainLab\User\Models\User', 'key' => 'user_id','otherKey'=>'id'],
    ];
    public $attachOne = [
        'pay_cover' => 'System\Models\File'
    ];
    /**
     * 用户搜索
     * @param $query
     * @param $field
     * @return bool
     */
    public function scopeTargetUser($query,$field)
    {
        $user=UserModel::where('userphone',$field)->orWhere('username',$field)->first();
        if(!$user){
            return false;
        }else{
            return $query->where('user_id',$user->id);
        }
    }

    /**
     * 状态筛选
     * @return mixed
     */
    public function getFilterStatusOptions()
    {
        return Config::get('summer.hjd::rg_status');
    }
}
